package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.pojo.Type;
import org.example.pojo.vo.PortalVo;
import org.example.service.HeadlineService;
import org.example.service.TypeService;
import org.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 宋孟林
 * @description
 */
@RestController
@RequestMapping("/portal")
@CrossOrigin
@Slf4j
public class PortalController {

    @Autowired
    private TypeService typeService;

    @Autowired
    private HeadlineService headlineService;

    /**
     * 获取所有分类
     * @return 分类列表
     */
    @GetMapping("/findAllTypes")
    public Result<Object> findAllTypes(){
      List<Type> list = typeService.findAllTypes();
      return Result.ok(list);
    }

    /**
     * 分页查询新闻
     * @param portalVo 1
     * @return 1
     */
    @PostMapping("/findNewsPage")
    public Result<Object> findNewsPage(@RequestBody PortalVo portalVo){
        return headlineService.findNewsPage(portalVo);
    }

    /**
     * 显示新闻详情
     * @param hid 1
     * @return 1
     */
    @PostMapping("/showHeadlineDetail")
    public Result<Object> showHeadlineDetail(int hid){
        return headlineService.findHeadlineVo(hid);
    }
}
